package com.proj.service.assembler;

import com.proj.beans.User;
import com.proj.entities.UserEntity;

import java.text.SimpleDateFormat;

public final class UserAssembler
{
    private UserAssembler()
    {
    }

    public static User getUserBean(UserEntity entity)
    {
        if (entity == null)
        {
            throw new IllegalArgumentException("UserEntity passed is null.");
        }

        User user = new User();
        user.setId(entity.getId());
        user.setUserName(entity.getUserName());
        user.setFirstName(entity.getFirstName());
        user.setLastName(entity.getLastName());
        user.setAddress(entity.getAddress());
        user.setAge(entity.getAge());
        user.setCity(entity.getCity());
        user.setEmail(entity.getEmail());
        user.setPhone(entity.getPhone());
        final SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        user.setCreatedOn(dateFormat.format(entity.getCreatedOn()));
        user.setUpdatedOn(dateFormat.format(entity.getUpdatedOn()));
        return user;
    }

    public static UserEntity getUserEntity(User user)
    {
        if (user == null)
        {
            throw new IllegalArgumentException("User bean passed is null");
        }

        UserEntity entity = new UserEntity();
        entity.setId(user.getId());
        entity.setUserName(user.getUserName());
        entity.setFirstName(user.getFirstName());
        entity.setLastName(user.getLastName());
        entity.setAddress(user.getAddress());
        entity.setCity(user.getCity());
        entity.setEmail(user.getEmail());
        entity.setAge(user.getAge());
        entity.setPhone(user.getPhone());
        return entity;
    }
}
